//
// Created by 常磊 on 2022/4/30.
//

import Foundation
import UIKit


extension UIButton {
    func setBackgroundColor(_ color: UIColor, for state: UIControl.State) {
        setBackgroundImage(.init(color: color), for: state)
    }
}

extension UIImage {
    convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
        let image = UIGraphicsImageRenderer(size: size).image { rendererContext in
            color.setFill()
            rendererContext.fill(CGRect(origin: .zero, size: size))
        }
        guard let cgImage = image.cgImage else {
            return nil
        }
        self.init(cgImage: cgImage)
    }
}